//
//  TYBaseTableView.m
//  Tunnel
//
//  Created by wbb on 2025/6/29.
//

#import "TYBaseTableView.h"
#import "CYLTableViewPlaceHolder.h"
@interface TYBaseTableView ()<CYLTableViewPlaceHolderDelegate>

@property (nonatomic, strong) TYBaseView * dataEmptyView;
@property (nonatomic, strong) UIImageView * emptyImgView;
@property (nonatomic, strong) UILabel * titleLab;

@end
@implementation TYBaseTableView

- (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style {
    self = [super initWithFrame:frame style:style];
    if(self) {
        _dataEmptyView = [[TYBaseView alloc] initWithFrame:CGRectMake(0, 0, kSCREEN_WIDTH, kSCREENH_HEIGHT-100)];
        
        UIImageView *emptyImgView = [[UIImageView alloc] init];
        emptyImgView.image = [UIImage imageNamed:@"empty_data"];
        [_dataEmptyView addSubview:emptyImgView];
        self.emptyImgView = emptyImgView;
        [emptyImgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.center.equalTo(_dataEmptyView);
        }];
        
        UILabel *lab = [[UILabel alloc] init];
        lab.text = @"暂无数据";
        lab.textColor = main_light_text_color_6;
        lab.font = [UIFont systemFontOfSize:10];
        [_dataEmptyView addSubview:lab];
        self.titleLab = lab;
        [lab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(emptyImgView.mas_bottom).offset(8);
            make.centerX.offset(0);
        }];
    }
    return self;
}

- (UIView *)makePlaceHolderView {
    switch ([WDGlobal shareInstance].emptyType) {
        case TYEmptyData:
        {
            self.emptyImgView.image = [UIImage imageNamed:@"empty_data"];
            self.titleLab.text = @"暂无数据";
        }
            break;
        case TYEmptyNetworkError:
        {
            self.emptyImgView.image = [UIImage imageNamed:@"network_error"];
            self.titleLab.text = @"网络异常";
        }
            break;
        case TYEmptyMessage:
        {
            self.emptyImgView.image = [UIImage imageNamed:@"message_error"];
            self.titleLab.text = @"暂无消息";
        }
            break;
        case TYEmptySearch:
        {
            self.emptyImgView.image = [UIImage imageNamed:@"search_empty"];
            self.titleLab.text = @"搜索无结果";
        }
            break;
        case TYEmptyLoadFail:
        {
            self.emptyImgView.image = [UIImage imageNamed:@"content_error"];
            self.titleLab.text = @"暂无数据";
        }
            break;
        default:
            break;
    }
    return self.dataEmptyView;
}
- (BOOL)enableScrollWhenPlaceHolderViewShowing {
    return YES;
}

//- (TYBaseView *)dataEmptyView {
//    if(!_dataEmptyView){
//        _dataEmptyView = [[TYBaseView alloc] initWithFrame:CGRectMake(0, 0, kSCREEN_WIDTH, kSCREENH_HEIGHT-100)];
//        
//        UIImageView *emptyImgView = [[UIImageView alloc] init];
//        emptyImgView.image = [UIImage imageNamed:@"empty_data"];
//        [_dataEmptyView addSubview:emptyImgView];
//        self.emptyImgView = emptyImgView;
//        [emptyImgView mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.center.equalTo(_dataEmptyView);
//        }];
//        
//        UILabel *lab = [[UILabel alloc] init];
//        lab.text = @"暂无数据";
//        lab.textColor = main_light_text_color_6;
//        lab.font = [UIFont systemFontOfSize:10];
//        [_dataEmptyView addSubview:lab];
//        self.titleLab = lab;
//        [lab mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.top.equalTo(emptyImgView.mas_bottom).offset(8);
//            make.centerX.offset(0);
//        }];
//    }
//    return _dataEmptyView;
//}
@end
